﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace System
{
	public static class ObjectExtensions
	{
		public static byte[] ToByteArray(this object o)
		{
			// create new memory stream
			MemoryStream memoryStream = new MemoryStream();

			// create new BinaryFormatter
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			binaryFormatter.Serialize(memoryStream, o);

			// convert stream to byte array and return
			return memoryStream.ToArray();
		}
	}
}